<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>资金统计</title>
    <link rel="stylesheet" type="text/css" href="./css/api.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/styleold.css" />
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript">
        function closeWin(){
            var setSele = 'randomSwitchBtn(2);';
            api.execScript({
                name: 'root',
                script: setSele,
            });
            api.closeToWin({
                name: 'root'
            });
        };
    </script>
</head>
<body>
    <!-- 头部 -->
    <header class="aui-bar aui-bar-nav pos" id="topbar">
        <a class="aui-pull-left aui-btn" onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">资金统计</div>
    </header>
    <div class="header-d"></div>
    <div id="list">
        <div class="my-fund-t">
            资产总额(元)
            <p>0.00</p>
        </div>
        <div class="my-fund-list aui-margin-b-15">
            <div class="aui-content">
                <ul class="aui-list aui-list-in">
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner aui-list-item-arrow" tapmode onclick="">
                            <div class="aui-list-item-title">可用余额(元)</div>
                            <div class="aui-list-item-right">0.00</div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner" tapmode onclick="">
                            <div class="aui-list-item-title">已获收益(元)</div>
                            <div class="aui-list-item-right">0.00</div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner aui-list-item-arrow" tapmode onclick="">
                            <div class="aui-list-item-title">待收收益(元)</div>
                            <div class="aui-list-item-right">0.00</div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner aui-list-item-arrow" tapmode onclick="">
                            <div class="aui-list-item-title">待收本金(元)</div>
                            <div class="aui-list-item-right">0.00</div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <div id="moneyList">
        <div class="cash-list">
           <ul>
             <li class="cash-list-1">
               <div class="aui-col-xs-2">
                 <span>支</span>
             </div>
             <div class="aui-col-xs-5 cash-list-m">
                提现手续费
                <p>0000-00-00 00:00:00</p>
            </div>
            <div class="aui-col-xs-5 cash-list-r">
               账户余额:00.00
               <p>支出:-0000.00</p>
           </div>
       </li>
   </ul>
</div>
</div>
</body>
<script type="text/template" id="template">
    <div class="my-fund-t">
        资产总额(元)
        <p>{{=it.total_money}}</p>
    </div>
    <div class="my-fund-list aui-margin-b-15">
        <div class="aui-content">
            <ul class="aui-list aui-list-in">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner aui-list-item-arrow" tapmode onclick="">
                        <div class="aui-list-item-title">可用余额(元)</div>
                        <div class="aui-list-item-right">{{=it.money}}</div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner" tapmode onclick="">
                        <div class="aui-list-item-title">已获收益(元)</div>
                        <div class="aui-list-item-right">{{=it.load_pay_earnings}}</div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner aui-list-item-arrow" tapmode onclick="">
                        <div class="aui-list-item-title">待收收益(元)</div>
                        <div class="aui-list-item-right">{{=it.load_wait_earnings}}</div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner aui-list-item-arrow" tapmode onclick="">
                        <div class="aui-list-item-title">待收本金(元)</div>
                        <div class="aui-list-item-right">{{=it.lock_money}}</div>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</script>
<script type="text/template" id="templateList">
   {{~it:value:index}}
   <div class="cash-list">
     <ul>
       <li class="cash-list-1">
         <div class="aui-col-xs-2">
           <span>
             {{? value.money < 0}}
             支
             {{??}}
             收
             {{?}}
         </span>
     </div>
     <div class="aui-col-xs-5 cash-list-m">
        {{=value.title  }}
        <p>{{=value.create_time}}</p>
    </div>
    <div class="aui-col-xs-5 cash-list-r">
     账户余额:{{=value.account_money}}
     <p>
      {{? value.money < 0}}
      支出:
      {{??}}
      收入:
      {{?}}
      {{=value.money}}</p>
  </div>    
</li>
</ul>
</div>
{{~}}
</script>
<script type="text/javascript">
    apiready = function(){
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err) {
            closeWin();
        });
        updateData();
        pullRefresh();
        pullLoading();
    };

    // 更新数据,模板函数
    function updateData(more){

        // 进度提示款
        api.showProgress({
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        var userid = $api.getStorage('userid');
        
        if (more)    {
            p += 1;
        }else {
            p = 1;
        }
        api.ajax({
            url: webAddress + '/index.php?ctl=app_user_center&act=statisticsmoney&p=' + p,
            method: 'post',
            data: {
                values: {
                    id: userid,
                },
            }
        },function(ret, err){
            // var ret = $api.jsonToStr(ret);
            // alert(ret);
            if (ret) {
                // 关闭下拉刷新控件
                api.refreshHeaderLoadDone();
                api.hideProgress();
                if (ret.status == 0) {
                    alert(ret.info);
                    return false;
                }else{  
                    var data = ret.user;
                    // 总资产
                    var total_money = outputmoney(ret.user.total_money);
                    data.total_money = total_money;
                    $api.setStorage('total_money', total_money);
                    // 可用余额
                    var money = outputmoney(ret.user.money);
                    data.money = money;
                    $api.setStorage('money', money);
                    // 已获收益
                    var load_pay_earnings = outputmoney(ret.user.load_pay_earnings);
                    data.load_pay_earnings = load_pay_earnings;
                    // 待获收益
                    var load_wait_earnings = outputmoney(ret.user.load_wait_earnings);
                    data.load_wait_earnings = load_wait_earnings;
                    // 冻结资金(待收本金)
                    var lock_money = outputmoney(ret.user.lock_money);
                    data.lock_money = lock_money;

                    var list = ret.list;
                    // 时间戳转换为时间 
                    // for (var i = 0; i < list.length; i++) { 
                    //     list[i].create_time = getDate(list[i].create_time)  ;
                    // }
                    // 调用模板函数
                    templateFun(data);
                    templateFunList(list);
                }
            } else {
                alert(err.msg);
                api.refreshHeaderLoadDone();
                api.hideProgress();
            }
        });
    };

    function changeTime(time) { 
        var time = new Date(time.replace("-","/"));
        //小时数
        var h = 8; 
        time.setHours(time.getHours() + h, time.getSeconds(), 0);   
        return time;
    }

    // 模板赋值函数
    function templateFun(data){
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var user = $api.byId('list');
        $api.html(user, html);
    }

    // 资金流水模板赋值函数
    function templateFunList(list){
        // if (p==7) {
        //     var list = $api.jsonToStr(list);
        //     alert(list);
        // }
        var template = $api.byId('templateList');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(list);
        var user = $api.byId('moneyList');
        if (p == 1) {
            $api.html(user, html);
        }else{
            if (list=='') {
                api.toast({
                    msg: '没有更多了..',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            $api.append(user, html);
        }
    }

    // 下拉刷新
    function pullRefresh(){
        api.setRefreshHeaderInfo({
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...'
        }, function(ret, err) {
            //在这里从服务器加载数据，加载完成后调用api.refreshHeaderLoadDone()方法恢复组件到默认状态
            updateData();
        });
    }

    // 上拉加载
    function pullLoading(){
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err){
            updateData(true);
        });
    }

    // 资金流水
    function cash_list(){
        var delay = 0;
        if(api.systemType != 'ios'){
            // delay = 300;
        }
        api.openWin({
            name: 'cash_list',
            url: './cash-list.html',
            bounces:false,
            delay: delay,
            slidBackEnabled:true,
            vScrollBarEnabled:false,
            progress:{
                type:"page"
            }
        });
    };

</script>
</html>